package com.ljh.controller;

import com.ljh.mapper.UserMapper;
import com.ljh.pojo.User;
import com.ljh.pojo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserMapper userMapper;
    @RequestMapping("/save")
    public void save(@RequestBody User user){
        user.setRegisterdate(new Date());
        userMapper.save(user);
    }
    @RequestMapping("/deleteById/{id}")
    public void delete(@PathVariable("id") long id){
        userMapper.deleteById(id);
    }
    @GetMapping("/findAll/{page}/{limit}")
    public UserVO findAll(@PathVariable("page") int page, @PathVariable("limit") int limit){
        UserVO userVO = new UserVO();
        userVO.setCode(0);
        userVO.setMsg("");
        userVO.setCount(userMapper.count());
        userVO.setData(userMapper.findAll((page-1)*limit,limit));
        return userVO;
    }
    @GetMapping("/count")
    public int count(){
        return userMapper.count();
    }
}
